package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.SmsHomeAdvertiseApi;
import com.mail.model.db.SmsHomeAdvertise;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author yan
 * @date 2022/06/23 14:28
 **/
@Service
public class SmsHomeAdvertiseService {
    @DubboReference
    private SmsHomeAdvertiseApi advertiseApi;

    public R create(SmsHomeAdvertise advertise) {
        advertiseApi.create(advertise);
        return R.success(null);
    }

    public R delete(List<Long> ids) {
        advertiseApi.delete(ids);
        return R.success(null);
    }

    public R list(String endTime, String name, Long pageNum, Long pageSize, Integer type) {
        SmsHomeAdvertise advertise = new SmsHomeAdvertise();
        advertise.setName(name);
        advertise.setType(type);
        Page<SmsHomeAdvertise> list = advertiseApi.list(advertise, pageNum, pageSize,endTime);
        PageResult pageResult = new PageResult(pageNum, pageSize, list.getTotal(), list.getRecords());
        return R.success(pageResult);
    }

    public R updateStatus(Long id, Integer status) {
        advertiseApi.updateStatusById(id, status);
        return R.success(null);
    }

    public R updateById(Long id, SmsHomeAdvertise advertise) {
        advertise.setId(id);
        advertiseApi.updateById(id, advertise);
        return R.success(null);
    }

    public R getAdvertiseById(Long id) {
        SmsHomeAdvertise advertise = advertiseApi.getAdvertiseById(id);
        return R.success(advertise);
    }
}
